package com.example.it.studyviewflipper;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;

import java.util.ArrayList;
import java.util.List;

public class HomeActivity extends AppCompatActivity implements GridView.OnItemClickListener {

    private GridView imagesGridView;
    public static List<Integer> ID_List;

    private void initFindView() {
        imagesGridView = (GridView) this.findViewById(R.id.gridView);
    }

    private void initGridView() {
        ID_List = new ArrayList<Integer>();
        ID_List.add(R.drawable.pet1);
        ID_List.add(R.drawable.pet2);
        ID_List.add(R.drawable.pet3);
        ID_List.add(R.drawable.pet4);
        ID_List.add(R.drawable.pet5);
        ID_List.add(R.drawable.pet6);
        ID_List.add(R.drawable.pet7);
        ID_List.add(R.drawable.pet8);
        ID_List.add(R.drawable.pet9);

        ImageGridViewAdapter adapter = new ImageGridViewAdapter(this, ID_List);
        this.imagesGridView.setAdapter(adapter);
    }

    private void registerEvent() {
        this.imagesGridView.setOnItemClickListener(this);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_home);

        initFindView();
        initGridView();
        registerEvent();
    }

    /**
     * Item的点击事件，点击Item后跳转到图片详情界面
     */
    @Override
    public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
        int id = (int) view.getTag();
        Intent intent = new Intent(this, AlbumActivity.class);
        intent.putExtra("currentId", id);

        this.startActivity(intent);

    }
}
